unit FormClassDataList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, FormClassEmptyList, ImgList,
  DB, ADODB, DBTables,
  Menus, ActnList,
  StdCtrls, Buttons, fcLabel, Grids, Wwdbigrd, Wwdbgrid, ExtCtrls,
  fcStatusBar, StdActns, XPMan;

type
  TfmFormClassDataList = class(TfmFormClassEmptyList)
    acEkle: TAction;
    acKaydet: TAction;
    acGuncelle: TAction;
    acSil: TAction;
    acVazgec: TAction;
    acYenile: TAction;
    miEkle: TMenuItem;
    miKaydet: TMenuItem;
    miGuncelle: TMenuItem;
    miIncele: TMenuItem;
    N1: TMenuItem;
    miSil: TMenuItem;
    miVazgec: TMenuItem;
    N3: TMenuItem;
    miYenile: TMenuItem;
    N4: TMenuItem;
    pnlButtonYeni: TPanel;
    btYeni: TBitBtn;
    pnlButtonSil: TPanel;
    btSil: TBitBtn;
    pnlButtonDuzelt: TPanel;
    btDuzelt: TBitBtn;
    pnlButtonIncele: TPanel;
    btIncele: TBitBtn;
    pnlButtonKaydet: TPanel;
    btKaydet: TBitBtn;
    pnlButtonVazgec: TPanel;
    btVazgec: TBitBtn;
    pnlButtonSec: TPanel;
    btSec: TBitBtn;
    procedure acEkleExecute(Sender: TObject);
    procedure aqEntryAfterCancel(DataSet: TDataSet);
    procedure aqEntryAfterOpen(DataSet: TDataSet);
    procedure FormShow(Sender: TObject);
    procedure grdListeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

  protected
    procedure ButtonWidthCaptionToRunTimeMode; override;
    procedure ButtonVisibleToRunTimeMode; override;
    procedure DesingFormToTerminal; override;
    procedure ActionKontrol(gState: TDataSetState); virtual;
  end;

var
  fmFormClassDataList: TfmFormClassDataList;

implementation

uses Boxes, data, Math, UnitOrtak;

{$R *.dfm}

procedure TfmFormClassDataList.ActionKontrol(gState: TDataSetState);
begin
  acEkle.Enabled := not (gState in [dsEdit, dsInsert]);
  acKaydet.Enabled := (gState in [dsEdit, dsInsert]);
  acGuncelle.Enabled := not (gState in [dsEdit, dsInsert]);
  acIncele.Enabled := not (gState in [dsEdit, dsInsert]);
  acSil.Enabled := not (gState in [dsEdit, dsInsert]);
  acVazgec.Enabled := (gState in [dsEdit, dsInsert]);
  acYenile.Enabled := not (gState in [dsEdit, dsInsert]);
  acKapat.Enabled := not (gState in [dsEdit, dsInsert]);
  {
    grdListe.ReadOnly := Not (gState In [dsEdit, dsInsert]);
    If (gState In [dsEdit, dsInsert]) Then
      grdListe.Options := grdListe.Options + [Wwdbigrd.dgEditing]
    Else
      grdListe.Options := grdListe.Options - [Wwdbigrd.dgEditing];
  }

  if (gState in [dsEdit, dsInsert]) then
    ControlSetting(Self, clWhite, False)
  else
    ControlSetting(Self, clInfoBk, True);

  grdListe.ReadOnly := False;
end;

procedure TfmFormClassDataList.ButtonWidthCaptionToRunTimeMode;
begin
  btSec.Width := IfThen(RunTimeMode = rtmTerminal, 48, 67);
  btYeni.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btKaydet.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btSil.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btDuzelt.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btVazgec.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btIncele.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);
  btKapat.Width := IfThen(RunTimeMode = rtmTerminal, 25, 67);

  btYeni.Caption := IfThen(RunTimeMode = rtmTerminal, '', btYeni.Caption);
  btKaydet.Caption := IfThen(RunTimeMode = rtmTerminal, '', btKaydet.Caption);
  btSil.Caption := IfThen(RunTimeMode = rtmTerminal, '', btSil.Caption);
  btDuzelt.Caption := IfThen(RunTimeMode = rtmTerminal, '', btDuzelt.Caption);
  btVazgec.Caption := IfThen(RunTimeMode = rtmTerminal, '', btVazgec.Caption);
  btIncele.Caption := IfThen(RunTimeMode = rtmTerminal, '', btIncele.Caption);
  btKapat.Caption := IfThen(RunTimeMode = rtmTerminal, '', btKapat.Caption);
end;

procedure TfmFormClassDataList.ButtonVisibleToRunTimeMode;
begin
  acEkle.Visible := RunTimeMode = rtmPC;
  acKaydet.Visible := RunTimeMode = rtmPC;
  acSil.Visible := RunTimeMode = rtmPC;
  acVazgec.Visible := RunTimeMode = rtmPC;
  acIncele.Visible := RunTimeMode = rtmPC;
  acGuncelle.Visible := RunTimeMode = rtmPC;
end;

procedure TfmFormClassDataList.DesingFormToTerminal;
begin
  inherited DesingFormToTerminal;
  if RunTimeMode = rtmTerminal then
  begin
    pnlHizliArama.Visible := False;
    ButtonWidthCaptionToRunTimeMode;
  end;
end;

procedure TfmFormClassDataList.acEkleExecute(Sender: TObject);
begin
  inherited;
  NavigatorKontrol(aqEntry, TAction(Sender).Tag);
end;

procedure TfmFormClassDataList.aqEntryAfterCancel(DataSet: TDataSet);
begin
  inherited;
  ActionKontrol(DataSet.State);
  ColumnDesign(DataSet.State);
  if aqEntry.Active then
  begin
    if aqEntry.RecNo >= 0 then
      lbNavigatorRecNo.Caption := '[ ' + IntToStr(aqEntry.RecNo) + ' / ' + IntToStr(aqEntry.RecordCount) + ' ]'
    else
      lbNavigatorRecNo.Caption := '[ 0 / 0 ]';
    paNavigatorRecNo.Left := 30;
    //If aqEntry.State In [dsInsert, dsEdit] Then
    //  grdListe.SetFocus;
  end;
end;

procedure TfmFormClassDataList.aqEntryAfterOpen(DataSet: TDataSet);
begin
  inherited;
  aqEntryAfterCancel(DataSet);
  //if (UseType = futSelect) and (aqEntry.Active) and (aqEntry.RecordCount = 1) then
  //  acSec.Execute;
end;

procedure TfmFormClassDataList.FormShow(Sender: TObject);
begin
  miEkle.Action := acEkle;
  miGuncelle.Action := acGuncelle;
  miKaydet.Action := acKaydet;
  miIncele.Action := acIncele;
  miSil.Action := acSil;
  miVazgec.Action := acVazgec;
  miKapat.Action := acKapat;
  miYenile.Action := acYenile;

  btSec.Action := acSec;
  btYeni.Action := acEkle;
  btDuzelt.Action := acGuncelle;
  btKaydet.Action := acKaydet;
  btIncele.Action := acIncele;
  btSil.Action := acSil;
  btVazgec.Action := acVazgec;

  inherited;

  acSec.Visible := UseType = futSelect;

  if UseType = futSelect then
    grdListe.SetFocus;

  if (m_szSQLWhere <> '') and (acSimdiAra.Tag <> 99) then
    acSimdiAra.Execute;
end;

procedure TfmFormClassDataList.grdListeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if Key = VK_INSERT then
    if (grdListe.DataSource.DataSet.Active) then
      acEkle.Execute;
end;

procedure TfmFormClassDataList.FormCreate(Sender: TObject);
begin
  inherited;
  DesingFormToTerminal;
end;

end.

